﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace Fitment
{
    public partial class _Default : System.Web.UI.Page
    {
        DS data = new DS();
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string account = tb_acc.Text.ToString().Trim();
            string pwd = tb_pwd.Text.ToString().Trim();
            string sql = "SELECT PASSWORD FROM INFO WHERE ROLLERID = '" + 2 + "' AND ACCOUNT = '"
                + account + "'";
            string pwd2 = data.ExcuteLogin(sql);
            if (pwd.Equals(pwd2))
            {
                sql = "SELECT User_ID,Name FROM UserInfo WHERE Account='"+account+"'";
                DataTable tb = data.GetDataSource(sql, "Query");
                //这里就是给session赋值

                Session["User_ID"] = tb.Rows[0][0];   //获取用户id
                Session["userName"] = tb.Rows[0][1];   //获取用户姓名  
                Response.Cookies["userID"].Value = Session["User_ID"].ToString();  //将值写入到客户端硬盘Cookie
                Response.Cookies["userID"].Expires = DateTime.Now.AddMinutes(10);//设置Cookie过期时间
               
                Response.Redirect("Index.aspx");
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "提示", "<script>alert('用户名或密码错误，请重新登录！');</script>");
            }
        }


    }
}
